package com.echo.fm.admin.auto;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.echo.fm.admin.auto.model.Admin;
import com.echo.util.ErrorException;
import com.echo.util.impl.TimerGet;

@Service("adminService")
public class DefaultAdminServiceImpl implements IAdminService {
	@Autowired
	@Qualifier("adminPersistence")
	protected IAdminPersistence adminPersistence;

	public IAdminPersistence getAdminPersistence() {
		return adminPersistence;
	}

	public void setAdminPersistence(IAdminPersistence adminPersistence) {
		this.adminPersistence = adminPersistence;
	}

	public Admin searchAdminUserByPhone(String phone) throws ErrorException {

		return adminPersistence.searchAdminUserByPhone(phone);
	}

	public boolean checkPassword(String id, String password) throws ErrorException {
		return adminPersistence.checkPassword(id, password);
	}

	public void registAdmin(String userName, String password, String phone) throws ErrorException {
		Admin admin = new Admin();
		admin.setPassword(password);
		admin.setUserName(userName);
		admin.setPhone(phone);
		admin.setT(TimerGet.getTimer());
		admin.setAdminId(UUID.randomUUID().toString().replaceAll("-", ""));
		adminPersistence.registAdminUser(admin);

	}

	public void updateUserById(Admin admin) throws ErrorException {
		adminPersistence.updateUserById(admin);
		
	}

	public void deleteUser(Admin admin) throws ErrorException {
		adminPersistence.deleteUser(admin);
		
	}

	public List<Admin> searchAdminList(String phone, String userName,Integer max,Integer firstNumber) throws ErrorException {
		return adminPersistence.searchAdminList(phone, userName, max, firstNumber);
	}


}
